<template>
	<view class="pages typeBg">
		<!-- 头部 -->
		<view class="header_bar header_fixed header_main">
			<view class="header">
				<view class="header-goBack" @tap.stop="$tools.back(1)"></view>
				<view class="header-title">{{ title }}</view>
			</view> 
		<view class="operateBox">
			<view class="operateBox-list">
				<view class="operateBox-list__item" @tap.stop="getNum()">
					<view class="title">销量</view>
					<image v-if="setNum == 0" class="upDown" src="@/static/shop/upDown.png" mode="widthFix"></image>
					<image v-if="setNum == 1" class="upDown" src="@/static/shop/upDown-1.png" mode="widthFix"></image>
					<image v-if="setNum == 2" class="upDown" src="@/static/shop/upDown-2.png" mode="widthFix"></image>
				</view>
				<view class="operateBox-list__item" @tap.stop="getPrice()">
					<view class="title">价格</view>
					<image v-if="setPrice == 0" class="upDown" src="@/static/shop/upDown.png" mode="widthFix"></image>
					<image v-if="setPrice == 1" class="upDown" src="@/static/shop/upDown-1.png" mode="widthFix"></image>
					<image v-if="setPrice == 2" class="upDown" src="@/static/shop/upDown-2.png" mode="widthFix"></image>
				</view>
			</view>
		</view>
	</view> 
		
		<!-- 商品列表 -->
		<view class="goodsListBox" :class="{'goodsListBox--mt' : cateId == '热销榜单'}">
			<goodsList :goodsDataList="goodsDataList"></goodsList>
		</view>
		
	</view> 
</template>

<script>
	import goodsList from '@/components/goodsList/goodsList.vue';
	export default {
		components:{
			goodsList
		},
		data(){
			return{
				pages: 1,
				pageIndex: 1,
				pageSize: 10,
				goodsDataList: [
					// {id: 1,storeName: '表现金美孚SP级0W-40全合成机油发动机润表现金美孚SP级0W-40全合成机油发动机润',price: '899.7',vipPrice: '999.00'},
					// {id: 1,storeName: '表现金美孚SP级0W-40全合成机油发动机润表现金美孚SP级0W-40全合成机油发动机润',price: '899.7',vipPrice: '999.00'},
					// {id: 1,storeName: '表现金美孚SP级0W-40全合成机油发动机润表现金美孚SP级0W-40全合成机油发动机润',price: '899.7',vipPrice: '999.00'},
					// {id: 1,storeName: '表现金美孚SP级0W-40全合成机油发动机润表现金美孚SP级0W-40全合成机油发动机润',price: '899.7',vipPrice: '999.00'},
					// {id: 1,storeName: '表现金美孚SP级0W-40全合成机油发动机润表现金美孚SP级0W-40全合成机油发动机润',price: '899.7',vipPrice: '999.00'},
				],
				isShowPage: false,
				setPrice: 0,
				setNum: 2,
				type:'', // 什么类型
				cateId: '',
				iStatusBarHeight: '',
				homeType:'',
				title:'热销榜单',
				systemParam:uni.getStorageSync('systemParam')?JSON.parse(uni.getStorageSync('systemParam')):{},
			}
		},
		onLoad(options) {
			this.type = options.value1;
			this.title = options.value3
			if(options.value1 =='热销榜单'){
				this.type = options.value1;
				if(options.value2){
					this.homeType = options.value2
				}
			}else{
				this.cateId = options.value2
			}
		},
		onShow() {
			// this.isShowPage = true;
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
			this.init();
		},
		onReachBottom() {
			console.log("ddd");
			if (this.pageIndex >= this.pages) {
				return this.$tools.toast('到底了');
			} else {
				this.pageIndex++;
				console.log("+++")
				this.getGoodsList();
			}
		},
		computed: {
			sortType(){
				if(this.setPrice == 0 && this.setNum == 0){
					return 3;
				}else if(this.setPrice != 0 && this.setNum == 0){
					return 2;
				}else if(this.setPrice == 0 && this.setNum != 0){
					return 1;
				}
			},
			sequence(){
				if(this.setPrice == 2 || this.setNum == 2){
					return 2;
				}else{
					return 1;
				}
			},
		},
		methods: {
			init(){
				this.isShowPage = false;
				this.pages = 1;
				this.pageIndex = 1;
				this.pageSize = 10;
				this.goodsDataList = [];
				this.getGoodsList();
			},
			// 查询商品推荐列表
			getGoodsList() {
				var data = {};
				console.log('homeType',this.cateId)
				if(this.type == '热销榜单'){
					data['zoneId'] = this.homeType;
					data['pageIndex'] = this.pageIndex;
					data['pageSize'] = this.pageSize;
					data['sortType'] = this.sortType; // 1. 销量高低排序  2. 价格高低排序  3随机排序(默认)
					data['sequence'] = this.sequence; // 1. 正序（默认）  2. 倒叙
					var url = '/api/product/discountList';
				}else{
					data['cateId'] = this.cateId;
					data['pageIndex'] = this.pageIndex;
					data['pageSize'] = this.pageSize;
					data['sortType'] = this.sortType; // 1. 销量高低排序  2. 价格高低排序  3随机排序(默认)
					data['sequence'] = this.sequence; // 1. 正序（默认）  2. 倒叙
					var url = '/api/product/discountList';
				}
				console.log("data:",data);
				// return;
				uni.showLoading({
					mask:true
				})
				this.$Ajax(url,data,res => {
					uni.hideLoading();
						if (res.code == 200) {
							this.pages = res.data.pages;
							this.goodsDataList = this.goodsDataList.concat(res.data.list);
							this.isShowPage = true;
						}
					}, err =>{
					}, 'GET'
				)
			},
			// 价格升降序
			getPrice(){
				let that = this;
				if(that.setPrice == 0){
					that.setPrice = 1;
				}else if(that.setPrice == 1){
					that.setPrice = 2;
				}else if(that.setPrice == 2){
					that.setPrice = 1;
				}
				that.setNum = 0;
				that.isShowPage = false;
				that.pageIndex = 1;
				that.goodsDataList = [];
				that.getGoodsList();
			},
			// 销量升降序
			getNum(){
				let that = this;
				if(that.setNum == 0){
					that.setNum = 1;
				}else if(that.setNum == 1){
					that.setNum = 2;
				}else if(that.setNum == 2){
					that.setNum = 1;
				}
				that.setPrice = 0;
				that.isShowPage = false;
				that.pageIndex = 1;
				that.goodsDataList = [];
				that.getGoodsList();
			},
		}
	}
</script>

<style lang="scss" scoped>
	page{
		background: #F5F5F5 !important;
	}
	.typeBg{
		width: 100%;
		background: #F5F5F5;
	}
	.header + uni-view{
		padding-top: 0 !important;
	}
	.operateBox{
		padding-top: 0 !important;
		width: 100%;
		// position: fixed;
		// /* #ifdef H5 */
		// top: 68rpx;
		// /* #endif */
		// /* #ifdef APP-PLUS */
		// top: 140rpx;
		/* #endif */
		z-index: 2;
		&-list{
			background: #F5F5F5;
			height: 80rpx;
			// padding: 20rpx 30rpx;
			@include flexBetween;
			&__item{
				@include flexCenter;
				margin-left: 30rpx;
				width: 50%;
				.title{
					font-family: PingFang SC, PingFang SC;
					font-weight: 400;
					font-size: 28rpx;
					color: #131414;
					margin-right: 12rpx;
				}
				image{
					width: 32rpx;
					height: 32rpx;
				}
			}
		}
	}
	.header_fixed + uni-view{
		/* #ifdef H5 */
		padding-top: 140rpx;
		/* #endif */
		/* #ifdef APP-PLUS */
		padding-top: calc(140rpx + var(--status-bar-height));
		/* #endif */
	}
	.goodsListBox{
		/* #ifdef H5 */
		padding-top: calc(88rpx + 80rpx);
		/* #endif */
		/* #ifdef APP-PLUS */
		padding-top: calc(164rpx);
		/* #endif */
		&--mt{
			margin-top: 20rpx;
		}
	}
</style>